			
<?python
	from kisp import *
	from sensors import *
  
	if poll:
		submit_url=url('/poll_edit/%s/' % poll.id )
		title_text="Edit Poll"
		
		poll_argument_filler = ''	
		arg_num = 0
		for argument in poll.arguments.split("\31"):
			poll_argument_filler += '$("#' + poll.sensor + '_sensor_argument_' + str(arg_num) + '").val("' + argument +'");\n'
			arg_num += 1

			
			
	else:
		title_text="Add Poll"
		submit_url=url('/poll_add/')

?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	  xmlns:xi="http://www.w3.org/2001/XInclude"
	  xmlns:py="http://genshi.edgewall.org/">
  <xi:include href="layout.html" />
  <head>
	<title>${title_text}</title>
  </head>
  <body class="poll">
<div id="center_column_item">
  <h1>${title_text}</h1>
	

<p>

<table><tbody>
<tr>
	<th><label>Sensor Used:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label></th>
	<td>
	<select width="100%" id="sensor_selector" name="sensor_selector" onchange="$('.sensor_pages').hide(); $('#' + this.value).show() ;">
	  <span py:for="sensor in KISP.plugins"> <option py:if="sensor.Type == 'Sensor'" value="${sensor.Name}">${sensor.Name} - ${sensor.Description}</option></span>
	  </select>

	  <span py:if="'sensor' in errors" class="error"><br />${errors.sensor}
	</span>
</td>
</tr>
</tbody></table>


<div py:for="sensor in KISP.plugins" class="sensor_pages" id="${sensor.Name}">
	<table><tbody>
<tr>
	<th><label>Poll Name:</label></th>
	<td>
	  <input type="text" width="100%" class="title" onblur="$('.'+this.className).val($(this).val())" id="${sensor.Name}_title"/>
	  <span py:if="'title' in errors" class="error">${errors.title}</span>
	</td>
  </tr><tr>
	<th><label>Minutes/Sample:</label></th>
	<td>
	  <input type="text" width="100%" class="minutes" onblur="$('.'+this.className).val($(this).val())" id="${sensor.Name}_minutes"/>
	  <span py:if="'minutes' in errors" class="error">${errors.minutes}</span>
	</td>
  </tr><tr>
	<th><label>Arguments:</label></th></tr><tr><td></td>
	<td>
	  
	  
	  <span py:if="'arguments' in errors" class="error">${errors.arguments}</span>

	  <div py:for="Argument in sensor.Arguments" >
		<input type="text" class="${sensor.Name}_arguments" id="${sensor.Name}_sensor_argument_${sensor.Arguments.index(Argument)}"/><br />
		${Argument} <br />
		</div>
	  
	  
	</td>

  </tr><tr>
	<td></td>
	<td>

	</td>
	</tr>
</tbody></table>
</div>



<form xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://genshi.edgewall.org/"  class="poll" action="${submit_url}" method="post">
	<span style="display:none">
	  Title:<input type="text" id="title" class="title" name="title"/><br/>
	  Minutes:<input type="text" id="minutes" class="minutes" name="minutes" /><br/>
	  Sensor:<input type="sensor" id="sensor" class="sensor" name="sensor" /><br/>
	  Arguments:<input type="text" id="arguments" name="arguments" /><br />
	</span>
	  <input type="submit" onclick="build_form_input()" value="Submit" />
	  <input type="submit" name="cancel" value="Cancel" />
</form>
</p>
</div>


<script type="text/javascript">
	function build_form_input()
	{	
		$("#sensor").val($("#sensor_selector").val());
		$("#title").val($("#" + $("#sensor_selector").val() + "_title").val());
		$("#minutes").val($("#" + $("#sensor_selector").val() + "_minutes").val());
 
		//$(".sensor_pages").hide();
		var argument_input = '';
		$("."+$("#sensor_selector").val()+"_arguments").each(
			
			function()
			{
				argument_input= argument_input + $(this).val() + "\31";
			}

		)
		$("#arguments").val(argument_input.slice(0,-1));

	}
</script>



<script py:if="poll" type="text/javascript">
  $(document).ready(function(){
	$("#sensor_selector").val("${poll.sensor}");
	$(".title").val("${poll.title}");
	$(".minutes").val("${'%d'%poll.minutes}");
	$("#arguments").val("${poll.arguments}")
	$(".sensor_pages").hide();
	$("#${poll.sensor}").show();
	${poll_argument_filler}
  });  
</script>

<script py:if="not poll" type="text/javascript">
  $(document).ready(function(){
	$(".sensor_pages").hide();
	$("#" + $("#sensor_selector").val()).show();
  });  
</script>

  </body>
</html>
